﻿using NUnit.Framework;
using NUnit.Framework.SyntaxHelpers;
using Rhino.Mocks;
using Tarantino.Core.Commons.Services.Security;
using Tarantino.Samples.Core.Model;
using Tarantino.Samples.Core.Services.Security;
using Tarantino.Samples.Core.Services.Security.Impl;

namespace Tarantino.Samples.UnitTests.Services.Security
{
	[TestFixture]
	public class SystemUserFactoryTester
	{
		[Test]
		public void Creates_system_user()
		{
			MockRepository mocks = new MockRepository();
			IEncryptionEngine engine = mocks.CreateMock<IEncryptionEngine>();

			using (mocks.Record())
			{
				Expect.Call(engine.Encrypt("clearTextPassword")).Return("encryptedPassword");
			}

			using (mocks.Playback())
			{
				ISystemUserFactory factory = new SystemUserFactory(engine);

				SystemUser systemUser = factory.CreateUser("khurwitz@hotmail.com", "clearTextPassword", "kevin", "hurwitz");

				Assert.That(systemUser.EmailAddress, Is.EqualTo("khurwitz@hotmail.com"));
				Assert.That(systemUser.Password, Is.EqualTo("encryptedPassword"));
				Assert.That(systemUser.FirstName, Is.EqualTo("kevin"));
				Assert.That(systemUser.LastName, Is.EqualTo("hurwitz"));
			}
		}
	}
}